#include<iostream>
#include<algorithm>
using namespace std;
int n;
bool check(int x)
{
	int sum = 0;
	int ans = 0;
	while (x) {
		int k = x % 10;
		sum += k;
		if (k == 6) {
			ans++;
		}
		x /= 10;
	}
	if (ans && sum % 6 == 0) {
		return 1;
	}
	return 0;
}
int main()
{
	cin >> n;
	int ans = 0;
	int ma = 0;
	for (int i = 1; i <= n; i++) {
		if (check(i)) {
			ans++;
			ma = max(i, ma);
		}
	}
	cout << ans << " " << ma << endl;
	return 0;
}